<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>数组创建和遍历</title>
</head>
<body>
    <script>

        //先定义后赋值
        var arr=[];
        arr[0]="zhangsan";
        arr[1]="18";
        arr[3]="nan";
        console.log(arr);
        
        //定义的时候赋值
        var arr2 = ["lisi",18,"男",180];
        console.log(arr2);
        

        var arr3=[100,[200,30],false];
        //多维数组访问
        //访问是下标要从0开始
        var a = arr3[1][1];//30
        console.log(a);

        //数组遍历
        //可以考虑使用for循环和while循环

        //for()循环
        var arr4 = ['zhangsan','18','nan'];
        var i = 0;
        for(i=0;i<arr4.length;i++)
        {
            console.log(arr4[i]);
        }
        
        //while()循环
        var k = 0;
        while(k<arr4.length)
        {
            console.log(arr4[k]);
            k++;  
        }
    </script>
</body>
</html>